'''

from tkinter import *

root = Tk()
root.title("我的第一个窗口")
root.geometry("400x300")
root.resizable(1,0)
root.configure(bg='black')
root.state('zoomed')
root.mainloop()






root = Tk()
root.geometry("300x200")

label = Label(root,text='Hello, Tkinter!',fg ='blue',justify=CENTER,font=("黑体",12))
label.pack()
root.state("normal")
root.mainloop()





from tkinter import *

def hander():
    message = et.get()
    result = eval(message)
    outcome.config(text=f'计算结果为:{result}')

root = Tk()
root.geometry('300x200')

lb = Label(root,text='请输入数学表达式:')
lb.pack()

et = Entry(root)
et.pack()

outcome = Label(root)
outcome.pack()

bt = Button(root,text='计算',command=hander)
bt.pack()

root.mainloop()





from tkinter import *

root = Tk()

textarea = Text(root)
textarea.pack()
textarea.insert('1.0','hello world')
textarea.insert('insert','python')
textarea.insert('end','this is an examp')

sr = Scrollbar(root,orient='horizontal',command=textarea.xview)
textarea['xscrollcommand'] = sr.set
sr.pack(fill='x')

root.mainloop()








from tkinter import *

def hander():
    result = age.get()
    if result == "":
        laber.config(text="Error,请选择一个选项")

    else:
        laber.config(text=f'您选择了{result}')

root = Tk()
root.geometry('300x200')
root.title('年龄分类表单')

age = StringVar()
choice_button1 = Radiobutton(root,text='未成年',variable=age,value='未成年')
choice_button1.pack()

choice_button2 = Radiobutton(root,text='成年',variable=age,value='成年')
choice_button2.pack()

choice_button3 = Radiobutton(root,text='老年',variable=age,value='老年')
choice_button3.pack()

laber = Label(root)
laber.pack()

button = Button(root,text="提交",command=hander)
button.pack()

root.mainloop()



from tkinter import *

def select():
    if (var1.get() == 0) and (var2.get() == 0) and (var3.get() == 0):
        label.config(text='您还未选择')
    else:
        if var1.get() == 1: 
            s1 = '李白'
        else:  
            s1 = ' '
        if var2.get() == 1: 
            s2 = "苏轼"
        else:  
            s2 = " "
        if var3.get() == 1: 
            s3 = '王维'
        else: 
            s3 = " "
        s=  '%s %s %s' % (s1, s2, s3)
        label.config(text=f'您选择了:{s}')

root = Tk()
root.geometry('300x200')
var1 = IntVar()
var2 = IntVar()
var3 = IntVar()

check1 = Checkbutton(root,text="李白",variable=var1)
check1.pack()

check2 = Checkbutton(root,text="苏轼",variable=var2)
check2.pack()

check3 = Checkbutton(root,text="王维",variable=var3)
check3.pack()

label = Label(root)
label.pack()

button = Button(root,text="提交",command=select)
button.pack()

root.mainloop()



from tkinter import *

def append():
    result = label.get()
    list_box.insert("end",result)
    label.delete(0,END)


root = Tk()
root.geometry('400x400')

list_box = Listbox(root)

meg = ['苹果','香蕉','橙子','葡萄','西瓜']
for i in meg:
    list_box.insert("end",i)
    


label = Entry(root)

button = Button(root,text="添加",command=append)

list_box.pack()
label.pack()
button.pack()
root.mainloop()





from tkinter import *

root = Tk()
root.geometry('400x400')
root.title("布局管理器实践")

frame1 = Frame(root,background="black")
frame1.pack(side="top",fill="x")
button1=Button(frame1,text="点击我")
button1.pack()

frame2 = Frame(root,background="blue",width=100,height=100)
frame2.place(relx=0.5,rely=0.5)
button2=Button(frame2,text="提交")
button2.pack()


frame3 = Frame(root,background="yellow")
frame3.grid()
button3=Button(frame3,text="点击按钮")
button3.pack()


root.mainloop()




from tkinter import *

def callback_function_enter(event):
    label.config(bg="red")

def callback_function_leave(event):
    label.config(bg="white")


root=Tk()
root.geometry('330x120')

label = Label(root,text="鼠标悬停在此标签上",font=('黑体',16))
label.pack(pady=20, padx=20)

label.bind("<Enter>", callback_function_enter)
label.bind("<Leave>", callback_function_leave)

root.mainloop()










from tkinter import *

Tk = Tk()
Tk.geometry('500x300')
Tk.title('布局管理器实践')
frame1 = Frame(Tk,padx=100,pady=10,bg='blue')
frame2 = Frame(Tk,padx=100,pady=10,bg='green')
frame3 = Frame(Tk,width=300,height=100,bg='red')
label1 = Label(frame1,text='frame1: 使用pack布局')
label2 = Label(frame2,text='frame2: 使用grid布局')
label3 = Label(frame3,text='frame3: 使用place布局')
entry = Entry(frame2)
button1 = Button(frame1,text='点击我')
button2 = Button(frame2,text='提交')
button3 = Button(frame3,text='点击按钮')

frame1.pack()
label1.pack()
button1.pack()

frame2.pack()
label2.grid(row=0,column=0)
entry.grid(row=0,column=1)
button2.grid(row=0,column=2)

frame3.place(x=120,y=140)
label3.place(x=0,y=30)
button3.place(x=90,y=70)

Tk.mainloop()







from tkinter import *

root = Tk()

menu = Menu(root)
def handler():
    print("点击了菜单")

menuitem = ['文件','编辑','视图','导航']
for item in menuitem:
    menu.add_command(label=item,command=handler)

root["menu"] = menu
root.mainloop()





from tkinter import *

root = Tk()

menu = Menu(root)
fmenu = Menu(root)

for item in ['新建','打开','保存']:
    fmenu.add_command(label=item)
menu.add_cascade(label="文件",menu=fmenu)

for item in ['编辑','视图','格式']:
    menu.add_command(label=item)

root['menu'] = menu
root.mainloop()




from tkinter import *

root = Tk()

menu = Menu(root)
fmenu = Menu(root)
menu2 = Menu(root)
for item in ['打开','保存','退出']:
    fmenu.add_command(label=item)

menu.add_cascade(label="文件",menu=fmenu)

for item in ['剪切','复制', '粘贴']:
    menu2.add_command(label=item)
def pop(event):
    menu2.post(event.x_root, event.y_root)
root.bind('<Button-3>', pop)

root['menu'] = menu
root.mainloop()


'''



from tkinter import *
from tkinter.messagebox import showinfo

def test():
    kg = float(entry1.get())
    cm = float(entry2.get())/100
    result = kg/(cm*cm)
    showinfo('您的BMI系数是:',result)


root = Tk()
root.title("BMI计算器")
root.geometry('500x300')
label1 = Label(root,text="输入体重(kg):")

entry1= Entry(root)

label2 = Label(root,text="输入身高(cm):")

entry2= Entry(root)

button = Button(root,command=test,text="计算BMI系数")

label1.pack()
entry1.pack()
label2.pack()
entry2.pack()
button.pack()


root.mainloop()




